package com.csdn.reposity;

import java.util.Map;
import java.util.ServiceLoader;
import java.util.concurrent.ConcurrentHashMap;
//仓库
public class ConfigReposityHolder {
    private static final Map<String, ConfigReposity> reposity = new ConcurrentHashMap<>();

    public static ConfigReposity get(String mode) {
        ConfigReposity configReposity = reposity.get(mode);
        if (configReposity == null) {
            synchronized (ConfigReposityHolder.class) {
                if (configReposity == null) {
                    ServiceLoader<ConfigReposity> serviceLoader = ServiceLoader.load(ConfigReposity.class);
                    for(ConfigReposity configReposity1:serviceLoader){
                        if(configReposity1.mode().equals(mode)){
                            configReposity = configReposity1;
                        }
                    }
                }
            }
        }
        return configReposity;
    }

}
